<?php

namespace App\Filament\Resources\Posts\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;

class PostsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('user.name')
                    ->label('作者')
                    ->searchable(),
                TextColumn::make('category.name')
                    ->label('分类')
                    ->searchable(),
                TextColumn::make('title')
                    ->label('标题')
                    ->searchable(),
                TextColumn::make('slug')
                    ->label('别名')
                    ->searchable()
                    ->toggleable(isToggledHiddenByDefault: true),
                ImageColumn::make('featured_image')
                    ->label('特色图片'),
                TextColumn::make('status')
                    ->label('状态')
                    ->badge(),
                TextColumn::make('visibility')
                    ->label('可见性')
                    ->badge(),
                TextColumn::make('published_at')
                    ->label('发布时间')
                    ->date()
                    ->sortable(),
                TextColumn::make('views_count')
                    ->label('浏览量')
                    ->numeric()
                    ->sortable(),
                TextColumn::make('likes_count')
                    ->label('点赞数')
                    ->numeric()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('comments_count')
                    ->label('评论数')
                    ->numeric()
                    ->sortable(),
                IconColumn::make('is_featured')
                    ->label('推荐')
                    ->boolean(),
                IconColumn::make('is_sticky')
                    ->label('置顶')
                    ->boolean(),
                TextColumn::make('meta_title')
                    ->label('SEO标题')
                    ->searchable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('created_at')
                    ->label('创建时间')
                    ->date()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->label('更新时间')
                    ->date()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('deleted_at')
                    ->label('删除时间')
                    ->date()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                TrashedFilter::make(),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}
